package com.gambi.tapestry.client;

import java.util.ArrayList;
import java.util.List;

import com.google.gwt.core.client.JavaScriptObject;

/*
 * Questa classe serve per fare il mapping tra il js ritornato e l'oggetto.
 * Viene chiamato in automatico a partire da la chiamata dentro onLoad
 */
public class TapestryGWTModule extends JavaScriptObject {

	protected TapestryGWTModule() {}

	public final List<TapestryGWTComponentInitializer> getComponentsDictionaries(){
		List<TapestryGWTComponentInitializer> result = new ArrayList<TapestryGWTComponentInitializer>();
		for( int i = 0; i < getComponentCount(); i++){
			result.add( getComponentInitializerAt( i ) );
		}
		return result;
	}
	
	public final native int getComponentCount()/*-{
		return this.length;
	}-*/;

	public final native TapestryGWTComponentInitializer getComponentInitializerAt( int index )/*-{
		if( index < this.length ){
			return this[ index ];
		} else {
			return null;
		}
	}-*/;

}
